package com.victor9ac.mashup.api.travel;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.victor9ac.mashup.api.Transport;

public class TravelRoute {

	
	String name,distance, duration, transferDuration;
	
	String priceRoute;
	
	List<Stop> stops;
	
	List<Transport> transport;

	public TravelRoute(String name, String distance, String duration,
			String transferDuration) {
		super();
		this.name = name;
		this.distance = distance;
		this.duration = duration;
		this.transferDuration = transferDuration;
	}

	
	

	
	void buildTransport() {
		String routeNameText = name;
		if (routeNameText != null){
			if (routeNameText.contains(",")){
				fillTransportComplexRoute(routeNameText);		
			}else{
				fillTransport(routeNameText);
			}		
		}
	}





	private void fillTransportComplexRoute(String routeNameText) {
		String[] routesDetected = routeNameText.split(",");
		for (int i=0;i<routesDetected.length;i++){
			String routePart = routesDetected[i];
			fillTransport(routePart);
		}
	}


	private void fillTransport(String routeNameText) {
		transport = this.getTransport();
		routeNameText = routeNameText.toLowerCase().trim();
		
		if (routeNameText.contains("bus")) {
			transport.add(Transport.BUS);
		} else if (routeNameText.contains("train")) {
			transport.add(Transport.TRAIN);
		} else if (routeNameText.contains("fly")) {
			transport.add(Transport.PLANE);
		} else if (routeNameText.contains("car")) {
			transport.add(Transport.CAR);
		} else if (routeNameText.contains("walk")) {
			transport.add(Transport.WALK);
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDistance() {
		return distance;
	}

	public void setDistance(String distance) {
		this.distance = distance;
	}

	public String getDuration() {
		return duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	public String getTransferDuration() {
		return transferDuration;
	}

	public void setTransferDuration(String transferDuration) {
		this.transferDuration = transferDuration;
	}

	public String getPriceRoute() {
		return priceRoute;
	}

	public void setPriceRoute(String priceRoute) {
		this.priceRoute = priceRoute;
	}



	public List<Stop> getStops() {
		if (stops == null){
			stops = new ArrayList<Stop>();
		}
		return stops;
	}



	public void setStops(List<Stop> stops) {
		this.stops = stops;
	}



	public List<Transport> getTransport() {
		if (transport == null){
			transport = new ArrayList<Transport>();
		}
		return transport;
	}





	public void setTransport(List<Transport> transport) {
		this.transport = transport;
	}
	
}
